//
// Created by imed on 2024/4/15.
//

#include "map"
#include "string"
#include "CmdTools.h"
#include "RenderTools.h"
#include "fstream"

void render_html_to_pdf(){
    char cBuf[CMD_RESULT_BUF_SIZE] = {0};
    std::string sCmdResult;
    std::string cmd = "wkhtmltopdf.exe"
                      " --enable-local-file-access"
                      " result.html"
                      " out.pdf";

    ExecuteCMD(cmd.c_str(), cBuf);
    sCmdResult = std::string(cBuf); // char * 转换为 string 类型
    printf("CMD Result: \n%s\n", sCmdResult.c_str());
}

void render_html_template(){
    std::map<std::string, std::string> sampleDict = {
            {"patient_name", "tacom"},
            {"patient_id", "20240321154555"},
            {"patient_sex", "男"},
            {"patient_age", "24"},
            {"patient_time", "2024-04-15"},
            {"patient_eye_right", "D:\\Projects\\p2024-hyperthyroidism-screening\\ReportTemplate\\SampleImage\\right.png"},
            {"patient_eye_left", "D:\\Projects\\p2024-hyperthyroidism-screening\\ReportTemplate\\SampleImage\\left.png"},
            {"patient_eye_right_analysis", "级别0, 正常"},
            {"patient_eye_left_analysis", "级别1， 正常"},
            {"patient_doctor_analysis", "正常 </br>, 建议健康生活"}
    };
    std::string result = RenderHtmlTemplate("D:\\Projects\\p2024-hyperthyroidism-screening\\ReportTemplate\\HtmlTemplate\\hospital.html",
                                         sampleDict);
    std::ofstream outStream("result.html", std::ios::out | std::ios::trunc);
    if(outStream.is_open()){
        outStream << result;
        outStream.close();
    }
}

int main(){
    render_html_template();
    render_html_to_pdf();
}